import yaml
import os

class OssConfig:
    def __init__(self, kwargs):
        self.store = kwargs.get('store')
        self.endpoint = kwargs.get('endpoint')
        self.id = kwargs.get('id')
        self.secret = kwargs.get('secret')
        self.bucket = kwargs.get('bucket')
        self.root = kwargs.get('root')
            

class AppConfig():

    def __init__(self, config_file_path):
        config_file_path = os.path.join(config_file_path, "config", "app.yaml")
        self.read_config(config_file_path)


    def read_config(self, file_path):
        with open(file_path, 'r') as file:
            try:
                yaml_data = yaml.safe_load(file)
                if 'app' in yaml_data:
                    app_config = yaml_data.get('app', {})
                    if 'oss' in app_config:
                        oss_config  = app_config.get('oss', {})
                        self.ossConfig = OssConfig(oss_config )
                    else:
                        raise ValueError("can not find oss config")
            
                else:
                    raise ValueError("can not find app config")

            except yaml.YAMLError as e:
                print(f"Error reading YAML file: {e}")
                return None
            